import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'
import { resolve } from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [uni()],
  resolve: {
    alias: {
      '@': resolve(__dirname, './'),
      '@/common': resolve(__dirname, './common'),
      '@/components': resolve(__dirname, './components'),
      '@/pages': resolve(__dirname, './pages'),
      '@/static': resolve(__dirname, './static'),
      '@/common/api': resolve(__dirname, './common/api'),
      '@/common/config': resolve(__dirname, './common/config'),
      '@/common/utils': resolve(__dirname, './common/utils'),
    }
  },
  // 服务器配置，用于开发环境
  server: {
    host: 'localhost',
    port: 8080,
    // 代理配置，用于解决跨域问题
    proxy: {
      '/api': {
        target: 'http://localhost:3000',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  }
})